package com.elloe.lesson;

import org.junit.jupiter.api.Test;

import java.util.Scanner;

/**
 * @author ElloeStudy(Sifa Zhang)
 * @create 2021-11-17 8:56
 * To: 真常应物，真常得性，常清常静，常清静矣
 */
public class Demo1 {
    public static void main(String[] args) {
        // 九九乘法表
        for (int i = 1 ; i < 10; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j+" * "+i+" = "+i*j+"  ");
            }
            System.out.println();
        }
    }
    @Test
    public void t1(){
        // 斐波那契数
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入： ");
        int n = Integer.parseInt(scanner.nextLine().trim());// 将字符串转换为int
        if (n<=0){
            System.out.println("输入错误！");
            return;
        }
        System.out.println("前"+n+"项为: ");
        int a=1,b=1,c=2;
        if (n==1){
            System.out.println(a);
            System.out.println("f("+n+") = "+a);
            return;
        }
        if (n==2){
            System.out.println(a+"\t"+b);
            System.out.println("f("+n+") = "+b);
            return;
        }
        if (n>=3){
            System.out.print(a+"\t"+b+"\t");
            for (int i = 3; i <= n; i++) {
                c= a + b;
                a = b;
                b = c;
                System.out.print(c+"\t");
                if (i%5==0){
                    System.out.println();
                }
            }
        }
        System.out.println("\n"+"f("+n+")="+c);
    }


    @Test
    public void t2(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入： ");
        int n = Integer.parseInt(scanner.nextLine().trim());
        if (n<=0){
            System.out.println("输入错误!");
            return;
        }
        for (int i = 1; i <= n; i++) {
            System.out.print(Fibonacci(i)+"\t");
            if (i==5){
                System.out.println();
            }
        }
        System.out.println("f("+n+") = "+Fibonacci(n));
    }

    public static int  Fibonacci(int n){
        // 递归出口，基线条件
            if (n==1 || n==2){
                return 1;
            }else{
                // 递归条件
                return Fibonacci(n-1)+Fibonacci(n-2);
            }
    }

    @Test
    public void t3(){
        // trim() 删除头尾部的字符串
        String s = new String("    www.baidu.com  ");
        System.out.println("原始值： ");
        System.out.println(s);

        System.out.println("删除头部空格符： ");
        System.out.println(s.trim());

    }
}
